package services;

import java.sql.SQLException;
import java.util.List;

import model.kml.Document;
import model.kml.Kml;
import model.kml.Placemark;
import model.kml.PolyStyle;
import model.kml.Style;
import DAO.SpatialDAO;

public class SpatialService {
	
	private SpatialDAO dao = new SpatialDAO();
	
	public String gerarAcudesKml() throws Exception{
		Document doc = new Document();
		doc.setName("Acudes.kml");
		PolyStyle polyStyle = new PolyStyle("afff0000", PolyStyle.NORMAL_COLOR_MODE);
		Style style = new Style();
		style.setId("defaultStyle");
		style.addGeometryStyle(polyStyle);
		doc.addStyle(style);
		List<Placemark> places = dao.getPlacemarksFromAcudeLayer(style);
		doc.setPlaces(places);
		Kml kml = new Kml();
		kml.addDocument(doc);
		return kml.toString();
	}

	public String gerarBufferKml() throws SQLException {
		Document doc = new Document();
		doc.setName("Buffer.kml");
		PolyStyle polyStyle = new PolyStyle("7f00ffff", PolyStyle.NORMAL_COLOR_MODE);
		Style bufferStyle = new Style();
		bufferStyle.setId("bufferStyle");
		bufferStyle.addGeometryStyle(polyStyle);
		doc.addStyle(bufferStyle);
		List<Placemark> places = dao.realizarConsultaBuffer(bufferStyle);
		doc.setPlaces(places);
		Kml kml = new Kml();
		kml.addDocument(doc);
		return kml.toString();
	}

	public String gerarAcudeSelectedKml(double lat, double lng) throws SQLException {
		Document doc = new Document();
		doc.setName("AcudeSelected.kml");
		PolyStyle polyStyle = new PolyStyle("af00ff00", PolyStyle.NORMAL_COLOR_MODE);
		Style style = new Style();
		style.setId("defaultStyle");
		style.addGeometryStyle(polyStyle);
		doc.addStyle(style);
		List<Placemark> places = dao.getAcudeSelected(lat,lng,style);
		doc.setPlaces(places);
		Kml kml = new Kml();
		kml.addDocument(doc);
		return kml.toString();
	}
}
